package com.shtel.paas.monitorcenter.view.dispaly.host.monitor.controller;

import java.util.ArrayList;
import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.shtel.paas.monitorcenter.view.dispaly.host.monitor.entity.SearchServerInfoEntity;
import com.shtel.paas.monitorcenter.view.dispaly.host.monitor.service.HostMonitorService;
import com.shtel.paas.monitorcenter.view.dispaly.host.monitor.vo.SearchServerInfoVo;
import com.shtel.paas.monitorcenter.view.dispaly.host.monitor.vo.selecthostMonitorTreeDataVo;
import com.shtel.paas.sdk.core.RefreshableRestController;
import com.shtel.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
 * 
 * @author zhongzhaochuan.zhong
 *
 */
@EnablePaasMybatis
@MapperScan("com.shtel.paas.monitorcenter.view.dispaly.host.monitor.mapper")
@RefreshableRestController
public class HostMonitorController {

	@Autowired
	HostMonitorService hostMonitorService;

	/**
	 * 获取每台服务器的基本信息
	 * 
	 * @param systemName
	 * @param belongAppliedSystem
	 * @return resultArray
	 */
	@GetMapping("/selectServerInfo")
	public SearchServerInfoVo selectServerInfo(
			@RequestParam("systemName") String systemName,
			@RequestParam("belongAppliedSystem") String belongAppliedSystem) {
		
		SearchServerInfoEntity rmpEnt = new SearchServerInfoEntity();
		rmpEnt.setSystemName(systemName);
		rmpEnt.setBelongAppliedSystem(belongAppliedSystem);

		SearchServerInfoVo resultArray = new SearchServerInfoVo();
		resultArray = hostMonitorService.selectServiceInfo(rmpEnt);
		return resultArray;
	}

	/**
	 * 获取Grafana信息
	 * 
	 * @param id
	 * @return url
	 */
	@GetMapping("/getGrafanaUrl")
	public String getGrafanaUrl(@RequestParam("id") Integer id) {

		String url = hostMonitorService.getGrafanaUrl(id);
		return url;
	}
	
	/**
	 * 动态获取动态树的第一到第二层节点数据
	 * @return resultArray
	 */
	@GetMapping("/selecthostMonitorTreeData")
	public List<Object> selecthostMonitorTreeData() {
		
		List<Object> resultArray = new ArrayList<>();
		resultArray = hostMonitorService.selecthostMonitorTreeData();
		return resultArray;
	}
	
	/**
	 * 异步获取动态树的第三层节点数据
	 * @return resultArray
	 */
	@GetMapping("/asyncSelectHostMonitorTreeData")
	public List<selecthostMonitorTreeDataVo> asyncSelectHostMonitorTreeData(@RequestParam("commentId") String commentId) {
		
		List<selecthostMonitorTreeDataVo> resultArray = new ArrayList<>();
		resultArray = hostMonitorService.asyncSelectHostMonitorTreeData(commentId);
		return resultArray;
	}
}
